package com.xmb.wcapi.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xmb.wcapi.entity.CustomQualityData;
import com.xmb.wcapi.entity.InitialStock;
import com.xmb.wcapi.entity.StockNow;
import com.xmb.wcapi.entity.StockNowRecord;
import com.xmb.wcapi.mapper.StockNowMapper;
import com.xmb.wcapi.mapper.StockNowRecordMapper;
import com.xmb.wcapi.service.ICustomQualityDataService;
import com.xmb.wcapi.service.IInitialStockService;
import com.xmb.wcapi.service.IStockNowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 现存量记录表 服务实现类
 * </p>
 *
 * @author huangping
 * @since 2024-07-24
 */
@Service
public class StockNowServiceImpl extends ServiceImpl<StockNowMapper, StockNow> implements IStockNowService {


    @Resource
    IInitialStockService initialStockService;

    /**
     * 现存量初始化
     */
    public void initStockNowData(String time){

        //获取现存量表所有数据
        long count = count();
        if (count < 1){
            //数据没有被初始化
            //获取期初库存
            List<InitialStock> initialStocks = initialStockService.list();
            List<StockNow> list = new ArrayList<>();
            for (InitialStock st : initialStocks) {
                StockNow stockNow = new StockNow();
                stockNow.setMaterial(st.getDjMaterial());
                stockNow.setTimes(DateUtil.parse(time));
                stockNow.setCreateTime(DateUtil.parse(time));
                stockNow.setMaterialSum(Long.valueOf(st.getInvSum()));
                list.add(stockNow);
            }

            if (!list.isEmpty()){
                saveBatch(list);
            }

        }

    }

}
